package au.com.iglootech.component;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.vaadin.data.Container;
import com.vaadin.data.Property;
import com.vaadin.ui.Table;

/**
 * basic table for application.
 * @author zhuhome
 *
 */
public class IGTTable extends Table {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String YES = "YES";
	private static final String NO = "NO";

	/**
	 * 
	 */
	public IGTTable() {
		super();
	}

	/**
	 * constructor.
	 * @param caption title
	 */
	public IGTTable(final String caption) {
		super(caption);
	}

	/**
	 * constructor.
	 * @param caption caption
	 * @param dataSource data source
	 */
	public IGTTable(final String caption, final Container dataSource) {
		super(caption, dataSource);
	}

	@Override
	protected final String formatPropertyValue(final Object rowId, final Object colId, final Property property) {
		if (property.getValue() != null) {
			// Format by property type
			if (property.getType() == Date.class) {
				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
				return df.format((Date) property.getValue());
			} else if (property.getType() == Boolean.class) {
				if (property.getValue() == null || (Boolean) property.getValue()) {
					return YES;
				} else {
					return NO;
				}
			}
		}

		return super.formatPropertyValue(rowId, colId, property);
	}
}
